//package com.qf.shoppinguser.config;
//
//import com.qf.shoppinguser.entity.User;
//import com.qf.shoppinguser.util.CacheManagerSevice;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//public class LoginInterceptor implements HandlerInterceptor {
//    @Autowired
//    CacheManagerSevice cacheManagerSevice;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        if (request.getRequestURL().toString().endsWith("/login")
////        ||request.getRequestURL().toString().endsWith("/saveInfo")
//        ) {
//            return true;
//        }
//        // 在这里进行用户登录状态的检查
//        System.out.println("拦截器启动");
//        String token = request.getHeader("token");
//        System.out.println(token+"===token");
//        Object o = cacheManagerSevice.get("user_" + token);
//        System.out.println(o);
////        JSONObject.toJavaObject(o, User.class);
//        User user = (User) cacheManagerSevice.get("user_"+token);
//        if (user == null) {
//            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
//            return false;
//        } else {
//            return true;
//        }
//    }
//
//    private Object getUserFromSessionOrCache(HttpServletRequest request) {
//        // 从 session 或缓存中获取用户信息
//        // 这里根据具体业务逻辑实现
//        return request.getSession().getAttribute("user");
//    }
//}
